jQuery(document).ready(function($) {
	var traipler_normal_price =  700.00,
		traipler_price =  349.00;
	
	updatePrices(traipler_price);
	
	$(".extra_time select").on("change",function(e){
    		var extra_time = isNaN(parseInt($(this).selectpicker('val'))) ? 0 : parseInt($(this).selectpicker('val'));
    		var temp_price = parseInt(traipler_price + (45.00 * extra_time));
    		
    		updatePrices(temp_price);
	})
	
	
	function updatePrices(temp_price){
		
		
		_temp_price = temp_price || 349.00;
	
		var total = addIva(_temp_price)//_temp_price + ((_temp_price/100)*22);
		
		
		$(".partial").text(_temp_price.formatMoney());
		
		$(".total .price").text(total.formatMoney());
		
		
		$("[name=partial_price]").val(_temp_price)
		$("[name=total_price]").val(total.formatMoney())
	
	}
	
	function addIva(price){
	
		var price_ivato = price + ((price/100)*22);
		return price_ivato;
	
	}
	
});

Number.prototype.formatMoney = function(c, d, t){
var n = this, 
    c = isNaN(c = Math.abs(c)) ? 2 : c, 
    d = d == undefined ? "," : d, 
    t = t == undefined ? "." : t, 
    s = n < 0 ? "-" : "", 
    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", 
    j = (j = i.length) > 3 ? j % 3 : 0;
   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
 };